import request from '@/utils/request';
import { stringify } from 'qs';
export async function allActive(payload) {
  return request(`/admin/activity/list`, {
    // return request(`${HOST_URL}/user/signin`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;'
    },
    body:`${stringify(payload)}`
  });
}

export async function saveActive(payload) {
  let reqPrams;
  reqPrams = `title=${payload.article_title}&coverPic=${payload.article_pic}&type=${payload.article_type}`;
  if(payload.articleId){
    reqPrams+=`&activityId=${payload.articleId}`;
  }
  if(payload.article_type=="活动预告"){
    if(payload.article_tag){
      payload.article_tag.split("，").map(tag => {
        reqPrams += `&tag=${tag}`;
      })
    }
    if(payload.article_category){
      payload.article_category.split("，").map(category=>{
        reqPrams+=`&category=${category}`
      })
    }
    reqPrams+=`&activityHoldTime=${payload.article_activityHoldTime}&summary=${payload.article_describe}&speaker=${payload.article_speaker}&relatedActivity=${payload.article_relatedActivity}&maxAttendCount=${payload.article_maxAttendCount}&attendPrice=${payload.article_attendPrice*100}&activityDownTime=${payload.article_activityDownTime}&activityStartTime=${payload.article_activityStartTime}&activityEndTime=${payload.article_activityEndTime}&address=${payload.article_address}`
  }else{
    reqPrams+=`&category=默认&tag=默认`
  }
  if(payload.article_detail){
    reqPrams+="&body="+encodeURIComponent(payload.article_detail);
  }
  return request(`/admin/activity/add`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;'
    },
    body: reqPrams
  });
}

export async function detailActive(payload) {
  return request(`/admin/activity/find/${payload}`);
}

export async function deleteActive(payload) {
  return request(`/admin/activity/delete/${payload.id}`);
}

export async function countArticle(payload) {
  return request(`/admin/activity/count`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;'
    },
    body:`${stringify(payload)}`
  });
}
export async function AllBook(payload) {
  return request(`/admin/activity/attend/users`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;'
    },
    body:`${stringify(payload)}`
  });
}

export async function changeArticleState(payload) {
  return request(`/admin/activity/state/${payload.id}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;'
    },
    body:`state=${payload.state}`
  });
}
